package co.baiku.boot.shiro.redis;


import co.baiku.boot.config.ShiroConfig;
import org.springframework.data.redis.core.RedisTemplate;

import java.util.Set;
import java.util.concurrent.TimeUnit;

public class RedisManager implements IRedisManager {
    private RedisTemplate<String, Object> redisTemplate;

    public RedisManager(ShiroConfig shiroConfig) {
        this.redisTemplate = shiroConfig.redisTemplate();
    }

    @Override
    public Object get(String key) {
        return getRedisTemplate().opsForValue().get(key);
    }

    @Override
    public void set(String key, Object value, int expire) {
        getRedisTemplate().opsForValue().set(key, value, expire, TimeUnit.SECONDS);
    }

    @Override
    public void del(String key) {
        getRedisTemplate().delete(key);
    }

    @Override
    public Set<String> keys(String key) {
        return getRedisTemplate().keys(key);
    }

    public RedisTemplate<String, Object> getRedisTemplate() {
        return redisTemplate;
    }
}
